#include "babl.h"
#include "extensions/util.h"
-
-#define INLINE inline
-
/*
* Implemented according to information read from:
*
return u.s[1];
}
-static INLINE long
+static long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
#else
-static INLINE long
+static long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
#endif
-static INLINE long
+static long
conv_F_D (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_D_F (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_16_8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_8_16 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
/*********/
-static INLINE long
+static long
conv_rgbaF_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_8 (src, dst, samples * 4);
return samples;
}
-#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
-
-static INLINE long
+static long
conv_rgbF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_8 (src, dst, samples * 3);
return samples;
}
-static INLINE long
+static long
conv_gaF_ga8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_8 (src, dst, samples * 2);
#define conv_gF_g8 conv_F_8
#define conv_gAF_gA8 conv_gaF_ga8
-static INLINE long
+static long
conv_rgbaF_rgba16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_16 (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgbF_rgb16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_16 (src, dst, samples * 3);
return samples;
}
-static INLINE long
+static long
conv_gaF_ga16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_16 (src, dst, samples * 2);
#define conv_gF_g16 conv_F_16
#define conv_gAF_gA16 conv_gaF_ga16
-static INLINE long
+static long
conv_rgba8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
return conv_8_F (src, dst, samples * 4) / 4;
}
-static INLINE long
+static long
conv_rgb8_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
return conv_8_F (src, dst, samples * 3) / 3;
}
-static INLINE long
+static long
conv_ga8_gaF (unsigned char *src, unsigned char *dst, long samples)
{
return conv_8_F (src, dst, samples * 2) / 2;
#define conv_gA8_gAF conv_ga8_gaF
#define conv_g8_gF conv_8_F
-static INLINE long
+static long
conv_rgbaF_rgbaD (unsigned char *src, unsigned char *dst, long samples)
{
conv_F_D (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgbaD_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
conv_D_F (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgba16_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_F (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgb16_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_F (src, dst, samples * 3);
return samples;
}
-static INLINE long
+static long
conv_ga16_gaF (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_F (src, dst, samples * 2);
#define conv_gA16_gAF conv_ga16_gaF
#define conv_g16_gF conv_16_F
-static INLINE long
+static long
conv_rgba16_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_8 (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgb16_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_8 (src, dst, samples * 3);
return samples;
}
-static INLINE long
+static long
conv_ga16_ga8 (unsigned char *src, unsigned char *dst, long samples)
{
conv_16_8 (src, dst, samples * 2);
#define conv_gA16_gA8 conv_ga16_ga8
#define conv_g16_g8 conv_16_8
-static INLINE long
+static long
conv_rgba8_rgba16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_8_16 (src, dst, samples * 4);
return samples;
}
-static INLINE long
+static long
conv_rgb8_rgb16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_8_16 (src, dst, samples * 3);
return samples;
}
-static INLINE long
+static long
conv_ga8_ga16 (unsigned char *src, unsigned char *dst, long samples)
{
conv_8_16 (src, dst, samples * 2);
/* alpha conversions */
-static INLINE long
+static long
conv_gaF_gAF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_gAF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
/* alpha stripping and adding */
-static INLINE long
+static long
conv_rgbaF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_rgbF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_gaF_gF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_gF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
/* colorchannel dropping and adding */
-static INLINE long
+static long
conv_gF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_gaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
/* other conversions coded for some optimisation reason or sumthin */
-static INLINE long
+static long
conv_rgbaF_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
-conv_rgbaF_rgbA16 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- float alpha = (*(float *) src + (4 * 3));
- int c;
-
- for (c = 0; c < 3; c++)
- {
- *(unsigned short *) dst = lrint (((*(float *) src) * alpha) * 65535.0);
- dst += 2;
- src += 4;
- }
- *(unsigned short *) dst = lrint (alpha * 65535.0);
- dst += 2;
- src += 4;
- }
- return samples;
-}
-
-static INLINE long
+static long
conv_rgbaF_rgb16 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
-conv_rgbP8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- int c;
-
- for (c = 0; c < 3; c++)
- {
- (*(float *) dst) = *(unsigned char *) src / 255.0;
- dst += 4;
- src += 1;
- }
- (*(float *) dst) = 1.0;
- dst += 4;
- src += 1;
- }
- return samples;
-}
-
-static INLINE long
+static long
conv_rgbA16_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
}
/*
- static INLINE long
+ static long
conv_rgb8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
return samples;
}
- static INLINE long
+ static long
conv_g8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
return samples;
}
- static INLINE long
+ static long
conv_rgb16_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
return samples;
}
- static INLINE long
+ static long
conv_gF_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
return samples;
}
*/
-static INLINE long
+static long
conv_rgba8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_rgbA8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
-conv_argb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_rgba8_argb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[3];
- dst[1] = src[0];
- dst[2] = src[1];
- dst[3] = src[2];
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_Argb8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_rgbA8_Argb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = src[3];
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_Prgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = 255;
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_rgbP8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- dst[3] = 255;
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_Prgb8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2];
- dst[1] = src[1];
- dst[2] = src[0];
- /*dst[3] = src[3]; */
- src += 4;
- dst += 3;
- }
- return samples;
-}
-
-
-/* FIXME: this is actually BGRP */
-static INLINE long
-conv_rgb8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[2]; /* blue */
- dst[1] = src[1]; /* green */
- dst[2] = src[0]; /* red */
- dst[3] = 255;
- src += 3;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
-conv_rgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- src += 3;
- dst += 4;
- }
- return samples;
-}
-
-static INLINE long
+static long
conv_rgb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
#define conv_rgb8_rgbA8 conv_rgb8_rgba8
-static INLINE long
-conv_rgbP8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- *(unsigned int *) dst = *(unsigned int *) src;
- dst[3] = 255;
- src += 4;
- dst += 4;
- }
- return samples;
-}
-
-#define conv_rgbP8_rgbA8 conv_rgbP8_rgba8
-
-static INLINE long
-conv_rgba8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
-{
- memcpy (dst, src, samples * 4);
- return samples;
-}
-
-#define conv_rgbA8_rgbP8 conv_rgba8_rgbP8
-
-static INLINE long
-conv_rgbP8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
-{
- long n = samples;
-
- while (n--)
- {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- src += 4;
- dst += 3;
- }
- return samples;
-}
-
-static INLINE long
+static long
conv_rgba8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
return samples;
}
-static INLINE long
+static long
conv_rgbA8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
long n = samples;
- static INLINE long
+ static long
conv_yuvaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
float *src_f = (float *) src;
}
-static INLINE long
+static long
conv_yuvF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
float *src_f = (float *) src;
return samples;
}
-
-/******* lab, xyz and rgb interaction, lifted from cpercep by adam d. moss */
-
-/*
- static const double Xn = 0.951;
- static const double Yn = 1.0;
- static const double Zn = 1.089;
- */
-
-#define LXN 0.312713F
-#define LYN 0.329016F
-
-static const double lxn = LXN;
-static const double lyn = LYN;
-static double xnn = LXN / LYN;
-static double znn = (1.0F - (LXN + LYN)) / LYN;
-
-
-static const double LRAMP = 7.99959199F;
-
-static INLINE long
-conv_rgbF_xyzF (unsigned char *src, unsigned char *dst, long samples)
-{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n = samples;
-
- while (n--)
- {
- float x, y, z;
- float red, green, blue;
-
- red = src_f[0];
- green = src_f[1];
- blue = src_f[2];
-
- x = 0.431 * red + 0.342 * green + 0.179 * blue;
- y = 0.222 * red + 0.707 * green + 0.071 * blue;
- z = 0.020 * red + 0.130 * green + 0.939 * blue;
-
- dst_f[0] = x;
- dst_f[1] = y;
- dst_f[2] = z;
- dst_f += 3;
- src_f += 3;
- }
- return samples;
-}
-
-static INLINE long
-conv_xyzF_rgbF (unsigned char *src, unsigned char *dst, long samples)
-{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n = samples;
-
- while (n--)
- {
- dst_f[0] = src_f[0];
- dst_f[1] = src_f[1];
- dst_f[2] = src_f[2];
- dst_f += 3;
- src_f += 3;
- }
- return samples;
-}
-
-static INLINE double
-ffunc (const double t)
-{
- if (t > 0.008856F)
- {
- return (cbrt (t));
- }
- else
- {
- return (7.787F * t + 16.0F / 116.0F);
- }
-}
-
-
-static INLINE double
-ffunc_inv (const double t)
-{
- if (t > 0.206893F)
- {
- return (t * t * t);
- }
- else
- {
- return ((t - 16.0F / 116.0F) / 7.787F);
- }
-}
-
-static INLINE long
-conv_labF_xyzF (unsigned char *src, unsigned char *dst, long samples)
-{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n = samples;
-
- while (n--)
- {
- float P;
- float X, Y, Z;
- float L, a, b;
-
- L = src_f[0];
- a = src_f[1];
- b = src_f[2];
-
- if (L > LRAMP)
- {
- P = Y = (L + 16.0F) / 116.0F;
- Y = Y * Y * Y;
- }
- else
- {
- Y = L / 903.3F;
- P = 7.787F * Y + 16.0F / 116.0F;
- }
-
- X = (P + a / 500.0F);
- X = xnn *ffunc_inv (X);
- Z = (P - b / 200.0F);
- Z = znn *ffunc_inv (Z);
-
-
- dst_f[0] = X;
- dst_f[1] = Y;
- dst_f[2] = Z;
- dst_f += 3;
- src_f += 3;
- }
- return samples;
-}
-
-static INLINE long
-conv_xyzF_labF (unsigned char *src, unsigned char *dst, long samples)
-{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n = samples;
-
- while (n--)
- {
- double ffuncY;
- float X, Y, Z;
- float L, a, b;
- X = src_f[0];
- Y = src_f[1];
- Z = src_f[2];
-
- if (Y > 0.0F)
- {
- if (Y > 0.008856F)
- {
- L = (116.0F * cbrt (Y)) - 16.0F;
- }
- else
- {
- L = (Y * 903.3F);
- }
- }
- else
- {
- L = 0.0;
- }
-
- ffuncY = ffunc (Y);
- a = 500.0F * (ffunc (X / xnn) - ffuncY);
- b = 200.0F * (ffuncY - ffunc (Z / znn));
-
- dst_f[0] = L;
- dst_f[1] = a;
- dst_f[2] = b;
- dst_f += 3;
- src_f += 3;
- }
- return samples;
-}
-
-/******* end of cpercep lift out **/
-
-
-#define MAX_CONVERSIONS 100
-
-typedef struct Conversion
-{
- int from_fmt;
- int to_fmt;
- int cost; /* cost of function,. calculated as ms to convert 1024*1024 samples */
- int loss; /* 0 maps ok, 1 precision loss, 2 alpha loss, 4 channel loss
- (should be dwelled further into) */
- void (*function)(unsigned char *src, unsigned char *dst, long samples);
-} Conversion;
-
int init (void);
int
o (rgbaF, rgbaD);
o (rgbaD, rgbaF);
+#ifdef USE_TABLES
+ if (!table_inited)
+ table_init ();
+#endif
+
return 0;
}